__module_name__ = 'Urban Dictionary'
__module_version__ = '1.1'
__module_description__ = 'Gets the Urban Dictionary'
__author__ = 'iCherry'

import hexchat
import requests

def ud(word, word_eol, userdata):
	try:
		r = requests.get('http://api.urbandictionary.com/v0/define', params={'term': word_eol[1]})
		data = r.json()['list'][0]
		hexchat.prnt('Urban Dictionary -> ' + data['word'] + ': ' + data['definition'])
	except:
		hexchat.prnt('Urban Dictionary: No Definition')
	return hexchat.EAT_ALL

def unload_cb(userdata):
    print(__module_name__, 'version', __module_version__, 'unloaded.')
    
hexchat.hook_command('ud', ud, help='UD <word>')
hexchat.hook_unload(unload_cb)
print(__module_name__, 'version', __module_version__, 'loaded.')